import os
import time
import logging
import traceback
import pydiscovery2

# init logger
if not os.path.exists("log"):
    os.mkdir("log")
log_format = "[%(levelname)s][%(pathname)s:%(lineno)d][%(asctime)s] %(message)s"
log_path = f"log/strategy_{time.strftime('%Y%m%d')}.log"
logging.basicConfig(level=logging.INFO, filename=log_path, format=log_format)
console = logging.StreamHandler()
console.setLevel(logging.INFO)
formatter = logging.Formatter(log_format)
console.setFormatter(formatter)
logging.getLogger().addHandler(console)

try:
    logging.info("pydiscovery2.event_loop()")
    pydiscovery2.event_loop()
except Exception as e:
    logging.error(traceback.format_exc())
    logging.error(e)
